<%-- 
    Document   : admin_locked
    Created on : Mar 24, 2012, 11:56:50 PM
    Author     : Ervin  James
--%>

<%@page import="java.util.ArrayList"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="ContentManagers.RoleManagers.AdminManager"%><%@page import="java.net.URLEncoder"%>
<%@page import="ContentManagers.Security.Hasher"%>
<%@page import="ContentManagers.Security.Validator"%>
<%@page import="ContentManagers.RoleManagers.AuthenticationManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%try{
            boolean check = false;
        
            check = new AuthenticationManager().inSuchDB(2, request, response);
            
            if(check == false)
               new AuthenticationManager().redirectToProperIndex(2, request, response);
            
            else
             {
        %>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/admin_int.css" />
        <script type='text/javascript' src='Javascript/adminjs.js'></script>
        
        <title>LOCKED ACCOUNTS</title>
    </head>
    <body>
        <%@ include file="admin_header.jsp"%>
        <% //Call admin header file. The header contains the links for other pages. %>
       
        <div id ="body_wrapper">
             <div id="product_manager_options" class="content_box" style="min-width: 950px;">
           
                <%
                out.println("LOCKED PRODUCT MANAGER ACCOUNTS<br><br>");

                ResultSet rs = new AdminManager().getDisabledPM();

                //check if no valid row / move forward
                if(rs == null || rs.first() == false){
                    out.println("No locked product manager accounts.<br><br>");
                }
                else {
                    //restart from before first row
                    rs.beforeFirst();

                    int indexNo = 0;
                    ArrayList indexer = new ArrayList();

                    while(rs.next())
                    {
                    indexer.add(indexNo, rs.getString("product_manager_id"));
                    %>
                    <div class="renewPassword">
                        <form name ="disabledAccount" method="post" onsubmit="" action="../ServletUnlockPM">
                        <%
                            out.println(rs.getString("username"));
                        %>
                        <input type="text" name="pmIndex" value="<%out.println(indexNo);%>" hidden/>        
                        <br><input type="submit" name="submit" value="Unlock Account"/>
                        <%
                        if((session.getAttribute("errorMessage"))!=null)
                        {
                            int formNo = Integer.parseInt(session.getAttribute("formNo").toString());
                            if((session.getAttribute("errorMessage"))== "1" && formNo==indexNo)
                                out.println("A database error has occured.");

                        }
                        %>
                        </form>
                        </div>
                        <br>
                    <%

                    indexNo++;
                    }
                    //make sure to clear error messages
                    session.removeAttribute("errorMessage");
                    //pass the array using session
                    request.getSession().setAttribute("indexer", indexer);

                }
                %>

                    <%
                out.println("LOCKED ACCOUNTING MANAGER ACCOUNTS<br><br>");

                ResultSet rs2 = new AdminManager().getDisabledAM();

                //check if no valid row / move forward
                if(rs2 == null || rs2.first() == false){
                    out.println("No locked accounting manager accounts.<br><br>");
                }
                else {
                    //restart from before first row
                    rs2.beforeFirst();

                    int indexNo = 0;
                    ArrayList indexer = new ArrayList();

                    while(rs2.next())
                    {
                    indexer.add(indexNo, rs2.getString("accounting_manager_id"));
                    %>
                    <div class="renewPassword">
                        <form name ="disabledAccount" method="post" onsubmit="" action="../ServletUnlockAM">
                        <%
                            out.println(rs2.getString("username"));
                        %>
                        <input type="text" name="amIndex" value="<%out.println(indexNo);%>" hidden/>        
                        <br><input type="submit" name="submit" value="Unlock Account"/>
                        <%
                        if((session.getAttribute("errorMessage2"))!=null)
                        {
                            int formNo = Integer.parseInt(session.getAttribute("formNo2").toString());
                            if((session.getAttribute("errorMessage2"))== "1" && formNo==indexNo)
                                out.println("A database error has occured.");

                        }
                        %>
                        </form>
                        </div>
                        <br>
                    <%

                    indexNo++;
                    }
                    //make sure to clear error messages
                    session.removeAttribute("errorMessage2");
                    //pass the array using session
                    request.getSession().setAttribute("indexer2", indexer);

                }
                %>

                        <%
                out.println("LOCKED CUSTOMER ACCOUNTS<br><br>");

                ResultSet rs3 = new AdminManager().getDisabledCustomer();

                //check if no valid row / move forward
                if(rs3 == null || rs3.first() == false){
                    out.println("No locked customer accounts.<br><br>");
                }
                else {
                    //restart from before first row
                    rs3.beforeFirst();

                    int indexNo = 0;
                    ArrayList indexer = new ArrayList();

                    while(rs3.next())
                    {
                    indexer.add(indexNo, rs3.getString("customer_id"));
                    %>
                    <div class="renewPassword">
                        <form name ="disabledAccount" method="post" onsubmit="" action="../ServletUnlockCustomer">
                        <%
                            out.println(rs3.getString("username"));
                        %>
                        <input type="text" name="customerIndex" value="<%out.println(indexNo);%>" hidden/>        
                        <br><input type="submit" name="submit" value="Unlock Account"/>
                        <%
                        if((session.getAttribute("errorMessage3"))!=null)
                        {
                            int formNo = Integer.parseInt(session.getAttribute("formNo3").toString());
                            if((session.getAttribute("errorMessage3"))== "1" && formNo==indexNo)
                                out.println("A database error has occured.");

                        }
                        %>
                        </form>
                        </div>
                        <br>
                    <%

                    indexNo++;
                    }
                    //make sure to clear error messages
                    session.removeAttribute("errorMessage3");
                    //pass the array using session
                    request.getSession().setAttribute("indexer3", indexer);

                }
                %>
            </div>
             </div>
           <%@ include file="admin_footer.jsp" %>
       <% //Call default footer file %>
        
    </body>
</html>

<% }
    }catch(Exception e)
        {   session = request.getSession();
            session.setAttribute("username", "xxxxdefaultxxxx");
            session.setAttribute("sessionID", "xxxxdefaultxxxx");
        
            response.sendRedirect("admin_index.jsp");}
            
%>